package com.gopi.remfilebrowser.gui;

import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class GUIUtil 
{
	
	public static void setUpDefaultLF()
	{
		try
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch(Exception nfe)
		{
			
		}
	}
	
	public static void fillRowWithComponent(Container container,Component comp,GridBagConstraints gc)
	{
		fillRowWithComponents(container,new Component[]{comp},null,gc);
	}
	
	public static void fillRowWithComponents(Container container,Component[] comps,GridBagConstraints gc)
	{
		fillRowWithComponents(container,comps,null,gc);
	}
	
	public static void fillRowWithComponents(Container container,Component[] comps,int[] size,GridBagConstraints gc)
	{
		GridBagConstraints gc1;
		if(gc!=null)
			gc1 = (GridBagConstraints) gc.clone();
		else
			gc1 = createDefaultGridBagConstraint();
		setOptimumInsets(gc1);
		int i = 0;
		for(Component comp : comps)
		{
			gc1.gridx++;
			if(size!=null)
				gc1.weightx = size[i++];
			container.add(comp,gc1);
		}
	}

	public static void fillComponent(Container con,Component comp)
	{
		GridBagConstraints gc = new GridBagConstraints();
		gc.gridx = gc.gridx = 0;
		gc.weightx = gc.weighty = 100;
		gc.fill = GridBagConstraints.BOTH;
		con.add(comp,gc);
	}
	
	public static void setOptimumInsets(GridBagConstraints gc)
	{
		gc.insets.top = gc.insets.bottom = gc.insets.left = gc.insets.right = 5;
	}
	
	public static JPanel createGridBagPanel()
	{
		JPanel pan = new JPanel(new GridBagLayout());
		return pan;
	}
	
	public static GridBagConstraints createDefaultGridBagConstraint()
	{
		GridBagConstraints gc = new GridBagConstraints();
		gc.gridx = gc.gridy = 0;
		gc.weightx = gc.weighty = 0;
		return gc;
	}
	
}
